package com.github.zengfr.project.stepchain.pipeline;

import java.util.Map;
import java.util.function.Function;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.zengfr.project.stepchain.IChain;
import com.github.zengfr.project.stepchain.IChainBuilder;
import com.github.zengfr.project.stepchain.IConditionLoopProcessor;
import com.github.zengfr.project.stepchain.IConditionSelector;
import com.github.zengfr.project.stepchain.IConditionSelectorProcessor;
import com.github.zengfr.project.stepchain.IConditionValidator;
import com.github.zengfr.project.stepchain.IPipeline;
import com.github.zengfr.project.stepchain.IProcessor;
import com.github.zengfr.project.stepchain.IProcessorBuilder;
import com.github.zengfr.project.stepchain.IStep;
import com.github.zengfr.project.stepchain.step.StepBuilder;

/**
 * @author zengfr QQ:362505707/1163551688 Email:zengfr3000@qq.com
 *         https://github.com/zengfr/stepchain-spring-boot-starter
 */
@Component
public class Pipeline  implements IPipeline {
	@Autowired
	protected IChainBuilder chainBuilder;
	@Autowired
	protected StepBuilder stepBuilder;
	@Autowired
	protected IProcessorBuilder processorBuilder;
	@Override
	public <A, B> IChain<A, B> createChain(Function<A, B> func) {
		return chainBuilder.createChain(func);
	}

	@Override
	public <A, B> IChain<A, B> createChain(IProcessor<A, B> processor) {
		return chainBuilder.createChain(processor);
	}

	@Override
	public <A, B, C> IChain<A, C> createChain(Function<A, B> func1, Function<B, C> func2) {
		return chainBuilder.createChain(func1, func2);
	}

	@Override
	public <A, B, C> IChain<A, C> createChain(IProcessor<A, B> processor1, IProcessor<B, C> processor2) {
		return chainBuilder.createChain(processor1, processor2);
	}

	@Override
	public <A, B, C> IChain<A, C> createChain(IProcessor<A, B> processor, IChain<B, C> chain) {
		return chainBuilder.createChain(processor, chain);
	}

	@Override
	public <A, B, C> IChain<A, C> createChain(IChain<A, B> chain1, IChain<B, C> chain2) {
		return chainBuilder.createChain(chain1, chain2);
	}

	@Override
	public <A, B, C> IChain<A, C> createChain(IChain<A, B> chain, IProcessor<B, C> processor) {
		return chainBuilder.createChain(chain, processor);
	}

	@Override
	public <T> IStep<T> createStep() {
		 
		return stepBuilder.createStep();
	}

	@Override
	public <T> IStep<T> createStep(int parallelCount) {
		return stepBuilder.createStep(parallelCount);
	}

	@Override
	public <T> IStep<T> createStep(String parallelCountConfigName) {
		return stepBuilder.createStep(parallelCountConfigName);
	}

	@Override
	public <A, B, C> IProcessor<A, C> createProcessor(IProcessor<A, B> first, IProcessor<B, C> second) {
	 
		return processorBuilder.createProcessor(first,second);
	}

	@Override
	public <I, O> IConditionLoopProcessor<I, O> createProcessor(IConditionValidator<I> validator, IProcessor<I, O> processor) {
		return processorBuilder.createProcessor(validator,processor);
	}

	@Override
	public <I, O> IConditionSelectorProcessor<I, Boolean, O> createProcessor(IConditionValidator<I> validator, IProcessor<I, O> first, IProcessor<I, O> second) {
		return processorBuilder.createProcessor(validator,first,second);
	}

	@Override
	public <I, S, O> IConditionSelectorProcessor<I, S, O> createProcessor(IConditionSelector<I, S> selector) {
		return processorBuilder.createProcessor(selector);
	}

	@Override
	public <I, S, O> IConditionSelectorProcessor<I, S, O> createProcessor(IConditionSelector<I, S> selector, Map<S, IProcessor<I, O>> branchs) {
		return processorBuilder.createProcessor(selector,branchs);
	}


}
